/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package babydisco.NN;

import java.util.ArrayList;
import org.encog.engine.network.activation.ActivationLinear;
import org.encog.ml.data.MLData;
import org.encog.ml.data.basic.BasicMLData;
import org.encog.neural.networks.BasicNetwork;
import org.encog.neural.networks.layers.BasicLayer;

/**
 *
 * @author Stefan
 */
public class AdaptiveFilter {
    private BasicNetwork network;
    
    public AdaptiveFilter(int inputNeurons, int hiddenNeurons){
        network = new BasicNetwork();
        BasicLayer inputLayer = new BasicLayer(new ActivationLinear(), true, inputNeurons);
        BasicLayer hiddenLayer = new BasicLayer(new ActivationLinear(), true, hiddenNeurons);
        BasicLayer outputLayer = new BasicLayer(new ActivationLinear(), true, 1);

        network.addLayer(inputLayer);
        network.addLayer(hiddenLayer);
        network.addLayer(outputLayer);

        network.getStructure().finalizeStructure();
    }
    
    public ArrayList<Double> compute(ArrayList<Double> input){
        double[] inp = new double[input.size()];
        for(int i = 0; i<input.size(); i ++){
            inp[i] = input.get(i);
        }

        BasicMLData in = new BasicMLData((double[]) inp);
        MLData out = network.compute(in);

        ArrayList<Double> output = new ArrayList<Double>();
        for(double d: out.getData()){
            output.add(d);
        }

        return output;
    }
}
